package com.db.daoImpl;

import com.db.dao.OrderRecordDao;
import com.db.entity.OrderRecord;
import com.db.utility.BaseDaoImpl;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Created by MAGI on 2014/12/14.
 */

@Repository
@Transactional
public class OrderRecordDaoImpl extends BaseDaoImpl<OrderRecord> implements OrderRecordDao {

    @Override
    public List<OrderRecord> findToday() {
        HibernateTemplate ht = super.gethTemplate();
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
        String date = sdf.format(new Date()).toString();
        List<OrderRecord> list = ht.find("from OrderRecord where date=?", date);
        if(list.isEmpty())
            return Collections.EMPTY_LIST;
        return list;
    }
}
